<?php
/**
 * Pertyler
 * Object Browser's Table's Objects Page
 *
 * @author	Emre Hasegeli <hasegeli@gmail.com>
 * @license	GNU General Public License v3
 */

namespace Pertyler;

require '../library/Pert/General/Link.php';

require '../library/Pert/General/Page.php';

require '../databaseModel/Table.php';

require '../databaseModel/Role.php';

require '../control/main.php';

if(empty(\Pert\Page::Get()->HREF()->ParentTable))
	return false;

if(empty(\Pert\Page::Get()->HREF()->ParentRow))
	return false;

if(empty(\Pert\Page::Get()->HREF()->Table))
	return false;

if(!($moderator = Role_Moderator::Select()))
	if(require '../control/Login.php')
		return;

require 'KoolControls/KoolAjax/koolajax.php';

require 'KoolControls/KoolTreeView/kooltreeview.php';

$treeView = new \KoolTreeView('treeView');

$treeView->imageFolder = $iconsFolder;

$treeView->showLines = true;

$link = new \Pert\Link('ObjectBrowser_relatedTablesColumnsObjects.php',
		'body');

$link->ParentTable = \Pert\Page::Get()->HREF()->ParentTable;

$link->ParentRow = \Pert\Page::Get()->HREF()->ParentRow;

$link->Table = \Pert\Page::Get()->HREF()->Table;

foreach(Table::Select(\Pert\Page::Get()->HREF()->Table)->SelectColumnArray() AS $column)
	if($column->RelatedTable())
		if($column->RelatedTable()->Id() == \Pert\Page::Get()->HREF()->ParentTable)
		{
			$link->Column = $column->Priority();

			$treeView->Add('root',
					\Pert\Page::Get()->ParentTable . $link->ParentRow . \Pert\Page::Get()->HREF()->Table . 'Related' . $column->Priority(),
					$column,
					false,
					'triangle_redS.gif',
					$link->Href());
		}

$treeView->isSubTree = true;

$treeView->width = '250px';

echo $treeView->Render();
